package com.exam.system.controller;

import com.exam.system.entity.ExamLibraryType;
import com.exam.system.entity.PageDTO;
import com.exam.system.service.ExamLibraryTypeService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "题库类型模块")
@RestController
@CrossOrigin
public class ExamLibraryTypeController {
    @Autowired
    private ExamLibraryTypeService examLibraryTypeService;

    @ApiOperation("查找所有题库类型并整理为树型表格结构")
    @GetMapping ("findAllExamLibraryTypeList")
    public List<ExamLibraryType> findAllExamLibraryTypeList(){
        return  examLibraryTypeService.findAllExamLibraryTypeList();
    }

    @ApiOperation("修改题库类型")
    @ApiImplicitParam(name = "examLibraryType",value = "修改的题库类型实体类，包含id和需要修改的题库类型名称",required = true)
    @PostMapping("updateLibraryType")
    public String updateLibraryType(@RequestBody ExamLibraryType examLibraryType){
        examLibraryTypeService.updateLibraryType(examLibraryType);
        return "true";
    }

    @ApiOperation("添加父题库类型下的子题库类型")
    @ApiImplicitParam(name = "examLibraryType",value = "添加的子题库类型实体类",required = true)
    @PostMapping("addChildLibraryType")
    public String addChildLibraryType(@RequestBody ExamLibraryType examLibraryType){
        examLibraryTypeService.addChildLibraryType(examLibraryType);
        return "true";
    }

    //addParentLibraryType
    @ApiOperation("添加父题库类型")
    @ApiImplicitParam(name = "examLibraryType",value = "添加的父题库类型实体类",required = true)
    @PostMapping("addParentLibraryType")
    public String addParentLibraryType(@RequestBody ExamLibraryType examLibraryType){
        System.out.println(examLibraryType.toString());
        examLibraryTypeService.addParentLibraryType(examLibraryType);
        return "true";
    }

    //禁用或启用题库类型
    @ApiOperation("禁用或启用题库类型")
    @ApiImplicitParam(name = "examLibraryType",value = "禁用或启用的题库类型实体类",required = true)
    @PostMapping("disableOrEnableLibraryType")
    public String disableOrEnableLibraryType(@RequestBody ExamLibraryType examLibraryType){
        System.out.println(examLibraryType.toString());
        examLibraryTypeService.disableLibraryType(examLibraryType);
        return "true";
    }
}
